package vip.zcn.mrn.config;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;
import vip.zcn.mrn.annotation.ApiCheck;

@Slf4j
@Aspect
@Component
public class ApiCheckAspect {

    @Pointcut("@annotation(vip.zcn.mrn.annotation.ApiCheck)")
    public void apiCheckMethods() {}

    @Before("apiCheckMethods() && @annotation(apiCheck)")
    public void beforeApiCall(JoinPoint joinPoint, ApiCheck apiCheck) {
        log.info("接口校验开始: {}", joinPoint.getSignature().toShortString());
        // 模拟校验逻辑，可替换为鉴权、参数验证等
        if (apiCheck.value().equals("forbidden")) {
            throw new RuntimeException("接口访问被禁止");
        }
    }
}
